#define rRCCAHB1CLKEN *((volatile unsigned long *)0x40023830)
	

#define rGPIOE_MODER *((volatile unsigned long *)0x40021000)
#define rGPIOE_OTYPER *((volatile unsigned long *)0x40021004)
#define rGPIOE_OSPEEDR *((volatile unsigned long *)0x40021008)
#define rGPIOE_PUPDR *((volatile unsigned long *)0x4002100C)
#define rGPIOE_ODR *((volatile unsigned long *)0x40021014)
#define rGPIOE_BSRR *((volatile unsigned long *)0x40021018)
	


#define rGPIOF_MODER *((volatile unsigned long *)0x40021400)
#define rGPIOF_OTYPER *((volatile unsigned long *)0x40021404)
#define rGPIOF_OSPEEDR *((volatile unsigned long *)0x40021408)
#define rGPIOF_PUPDR *((volatile unsigned long *)0x4002140C)
#define rGPIOF_ODR *((volatile unsigned long *)0x40021414)
#define rGPIOF_BSRR *((volatile unsigned long *)0x40021418)
	

#define on 1
#define off 0
void led_init(void)
{
	unsigned long r_value;
	//en zhe GPIOE GPIOF COLOCK 进行时钟使能
	rRCCAHB1CLKEN |= (1<<4) | (1<<5);
	
	// moder out-01 PF9,PF10-[21:18] <-- 0101
	r_value = rGPIOF_MODER;
	r_value &= ~(0xf << 18);
	r_value |= (1 << 18) | (1<<20);
	rGPIOF_MODER = r_value;
	
	// moder out-01 PE13,PE14-[29:26]<--0101
	r_value = rGPIOE_MODER;
	r_value &= ~(0xf << 26);
	r_value |= (1 << 26) | (1<<28);
	rGPIOE_MODER = r_value;
	
	// moder out-01 PF9,PF10-[10,9]<--0
	r_value = rGPIOF_OTYPER;
	r_value &= ~(0x3 << 9);
	rGPIOF_OTYPER = r_value;
	
	// moder out-01 PE13,PE14-[14,13]<--0
	r_value = rGPIOE_OTYPER;
	r_value &= ~(0x3 << 13);
	rGPIOE_OTYPER = r_value;
	
	// moder out-01 PF9,PF10-[21,18]<--1010
	r_value = rGPIOF_OSPEEDR;
	r_value &= ~(0xf << 18);
	r_value |= (1 << 19) | (1<<21);
	rGPIOF_OSPEEDR = r_value;
	
	// moder out-01 PE13,PE14-[29,26]<--1010
	r_value = rGPIOE_OSPEEDR;
	r_value &= ~(0xf << 26);
	r_value |= (1 << 29) | (1<<27);
	rGPIOE_OSPEEDR = r_value;
	
	// moder out-01 PF9,PF10-[21,18]<--0000
	r_value = rGPIOF_PUPDR;
	r_value &= ~(0xf << 18);
	rGPIOF_PUPDR = r_value;
	
	// moder out-01 PE13,PE14-[29,26]<--0000
	r_value = rGPIOE_PUPDR;
	r_value &= ~(0xf << 26);
	rGPIOE_PUPDR = r_value;
	
	// led1,led2 - ODR(1)
	r_value = rGPIOF_BSRR;
	r_value |= (1<<9)|(1<<10);
	rGPIOF_BSRR = r_value;
	
	// led3,led4 - ODR(1)
	r_value = rGPIOE_BSRR;
	r_value |= (1<<13)|(1<<14);
	rGPIOE_BSRR = r_value;
}

void led1_ctrl(int status){
	if(status){
		rGPIOF_BSRR |= (1<<25);
	}else{
		rGPIOF_BSRR |= (1<<9);
	}
	
}
void led2_ctrl(int status){
	if(status){
		rGPIOF_BSRR |= (1<<26);
	}else{
		rGPIOF_BSRR |= (1<<10);
	}
	
}
void led3_ctrl(int status){
	if(status){
		rGPIOE_BSRR |= (1<<29);
	}else{
		rGPIOE_BSRR |= (1<<13);
	}
	
}
void led4_ctrl(int status){
	if(status){
		rGPIOE_BSRR |= (1<<30);
	}else{
		rGPIOE_BSRR |= (1<<14);
	}
}
void led_ctrl(int light_type){
	switch (light_type){
		case 0:{
			led1_ctrl(on);
			led2_ctrl(off);
			led3_ctrl(off);
			led4_ctrl(on);
			break;
		}
		case 1:{
			led1_ctrl(off);
			led2_ctrl(on);
			led3_ctrl(on);
			led4_ctrl(off);
			break;
		}
		case 2:{
			led1_ctrl(off);
			led2_ctrl(off);
			led3_ctrl(off);
			led4_ctrl(off);
			break;
		}
		case 3:{
			led1_ctrl(on);
			led2_ctrl(on);
			led3_ctrl(on);
			led4_ctrl(on);
			break;
		}
		default:
		break;
	}
}
void delay(int v) {
    while (v--);
}

int main(){
	int delay_time = 0x144444;
	int light_type = 0;
	led_init();
	while(1){
		led_ctrl(light_type++ % 4);
		delay(delay_time);
	}
}